package com.wn.controller;

import com.wn.annotation.RequireRoles;
import com.wn.entity.PageParam;
import com.wn.entity.Proposal;
import com.wn.service.ProposalService;
import com.wn.utils.Rsp;
import com.wn.utils.SystemControllerLog;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Date;

/**
 * (Proposal)表控制层
 *
 * @author makejava
 * @since 2020-11-03 12:58:09
 */
@RestController
@RequestMapping("proposal")
public class ProposalController {
    /**
     * 服务对象
     */
    @Resource
    private ProposalService proposalService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Proposal selectOne(String id) {
        return this.proposalService.queryById(id);
    }

    @SystemControllerLog(description = "添加单个信息")
    @RequireRoles(roles = {"admin","super_admin","reception","guide","tourist"},index = 1)
    @PostMapping("/addOneProposal")
    @ApiOperation("添加单个")
    public Rsp addOne(@RequestBody @Valid Proposal proposal, @RequestHeader("token") String token){

        //catering.setCreateuserid("1");
        proposal.setCreatetime(new Date());
        proposal.setIsdeleted(0);
        return proposalService.insert(proposal) == 1?Rsp.success(null).msg("添加成功"):Rsp.fail().msg("添加失败");
    }

    @RequireRoles(roles = {"super_admin","admin"},index = 1)
    @PostMapping("/updatePro")
    @ApiOperation("动态修改")
    public Rsp updateNewscategory(@RequestBody Proposal proposal,@RequestHeader("token") String token){


//        newsorder.setUpdateuserid("1");
        return proposalService.updateId(proposal);
    }


    @RequireRoles(roles = {"super_admin","admin"},index = 1)
    @PostMapping("/deleteOneNewsUserTrue")
    @ApiOperation("通过ID逻辑删除")
    public Rsp deleteOneNewscategoryTrue(@RequestBody Proposal proposal,@RequestHeader("token") String token){
//        newsorder.setUpdateuserid("1");
        return proposalService.deleteOneTrue(proposal.getId());
    }

    @PostMapping("/searchSomeNewsProByPage")
    @RequireRoles(roles = {"admin","super_admin","reception","guide","tourist"},index = 1)
    @ApiOperation("查询所有 支持 多条件 分页 排序 查询")
    public Rsp searchSomeByPage(@RequestBody PageParam<Proposal> orderPageParam, @RequestHeader("token") String token) {

        return Rsp.success(proposalService.searchSomeByPage(orderPageParam));
    }

}
